﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Settings;

namespace SMSROUTER.Business
{
    public partial class SmsGateway
    {
        #region Static method
        public static string GetNameByID(DBDataContext context, string gatewayID)
        {
            try
            {
                return context.SmsGateways.FirstOrDefault(p => p.GatewayID == gatewayID).GatewayName;
            }
            catch
            {
                return "";
            }
        }

        public static List<SmsGateway> Paging(DBDataContext context, int currentPage, int pageSize, ref int totalRecord, string gatewayId, string gatewayname)
        {
            var resutl = context.SmsGateways.AsQueryable();
            if (!string.IsNullOrWhiteSpace(gatewayId))
            {
                resutl = resutl.Where(p => p.GatewayID == gatewayId);
            }
            if (!string.IsNullOrWhiteSpace(gatewayname))
            {
                resutl = resutl.Where(p => p.GatewayName == gatewayname);
            }
            totalRecord = resutl.Count();
            return resutl.Skip(((currentPage - 1) < 0 ? 0 : (currentPage - 1)) * pageSize).Take(pageSize).ToList();
        }
        #endregion
    }
}
